#include <queue>
using std::queue;
#include <vector>
using std::vector;
#include <string>
using std::string;
#include <iostream>
using std::cout;
using std::endl;

struct TreeNode {
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode() : val(0), left(nullptr), right(nullptr) {}
    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
    TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
};

TreeNode* create_tree(int * arr, int len)
{   
    if (len < 1)
        return nullptr;
    TreeNode* head = new TreeNode(arr[0]);
    queue<TreeNode*> q;
    q.push(head);
    for(int i = 1; i < len; ++i)
    {
        TreeNode* t = q.front();
        q.pop();
        if (i < len && arr[i] != -1)
        {
            TreeNode* l = new TreeNode(arr[i]);
            t->left = l;
            q.push(l);
        }
        i += 1;
        if (i < len && arr[i] != -1)
        {
            TreeNode* r = new TreeNode(arr[i]);
            t->right = r;
            q.push(r);
        }
    }
    return head;
}

TreeNode* create_tree(vector<int> arr){
    int list[arr.size()];
    std::copy(arr.begin(), arr.end(), list);
    return create_tree(list, arr.size());
}

TreeNode* get_tree_node(TreeNode* root, int val){
    if(root == nullptr) return nullptr;

    if(root->val == val) return root;

    TreeNode* res = nullptr;
    if(root->left != nullptr) res = get_tree_node(root->left, val);
    if(res != nullptr) return res;
    if(root->right != nullptr) res = get_tree_node(root->right, val);
    return res;
}

void show(TreeNode* tree, string s=""){
    if (tree == nullptr){
        cout << s << "NONE" << endl;
        return;
    }

    cout << s << tree->val << endl;
    s = s + "  ";

    show(tree->left, s);
    show(tree->right, s);
}